<template>
	<view :class="isShowEmptyData ? 'content-empty' : 'content'">
		<view class="empty_data" v-if="isShowEmptyData">
			<view class="empty_data_content">
				<image class="empty_data_image" src="../../../../static/empty_data.png" mode="widthFix"></image>
				<view class="empty_data_title">暂无数据</view>
			</view>
		</view>
		<view v-else>
			<image :src="buildInfo.thumb" mode="aspectFill" style="max-height: 800rpx;"></image>

			<view class="header header_more">
				<view class="horizontal">
					<view class="line"></view>
					<view class="header_title">基本信息</view>
				</view>
				<image class="share_image" src="../../../../static/share.png" mode="widthFix"></image>
			</view>
			<view class="info_list">
				<view class="info_item">
					<text class="info_item_name">地&emsp;&emsp;区</text>
					<text class="info_item_value">{{ buildInfo.area.name }}</text>
				</view>
				<view class="info_item">
					<text class="info_item_name">楼盘名称</text>
					<text class="info_item_value">{{ buildInfo.name }}</text>
				</view>
				<view class="info_item">
					<text class="info_item_name">户&emsp;&emsp;型</text>
					<text class="info_item_value">{{ buildInfo.model.name }}</text>
				</view>
			</view>
			<view class="header">
				<view class="line"></view>
				<view class="header_title">地理位置</view>
			</view>
			<view class="map_container"><map @click="openMap" :latitude="buildInfo.latitude" :longitude="buildInfo.longitude" :markers="covers"></map></view>
			<view class="header">
				<view class="line"></view>
				<view class="header_title">案例展示</view>
			</view>
			<view class="list">
				<view class="item" v-for="index in 4" :key="index" @click="openDetailsSample">
					<view v-if="index % 2 == 1">
						<image src="../../../../static/builder_simple1.png" mode="widthFix"></image>
						<view class="item_range">30m²</view>
					</view>
					<view v-else>
						<image src="../../../../static/builder_simple2.png" mode="widthFix"></image>
						<view class="item_range">80m²</view>
					</view>
				</view>
			</view>
			<view class="btn" hover-class="btn_hover" type="default" size="mini" @click="isShowConfirm = true">预约</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			buildInfo: {
				area: {},
				model: {}
			},
			covers: [
				{
					latitude: 0,
					longitude: 0,
					iconPath: '../../../../static/location.png'
				}
			],
			isShowEmptyData: true
		};
	},
	onLoad(e) {
		uni.request({
			url: 'https://baiyi.kent.work/api/v1/system/getBuildDetail',
			method: 'POST',
			data: {
				id: e.id
			},
			success: res => {
				console.log(res);
				if (res.data.code == 200) {
					this.isShowEmptyData = false;
					this.buildInfo = res.data.data.buildInfo;
					this.covers[0].latitude = parseFloat(this.buildInfo.latitude);
					this.covers[0].longitude = parseFloat(this.buildInfo.longitude);
				} else {
					this.isShowEmptyData = true;
				}
			},
			fail: e => {
				this.isShowEmptyData = true;
			}
		});
	},
	methods: {
		openMap() {
			uni.navigateTo({
				url: `/pages/index/builder/details/map/map?id=${this.buildInfo.id}`
			});
		},
		openDetailsSample() {
			uni.navigateTo({
				url: '/pages/index/builder/details/sample/sample'
			});
		}
	}
};
</script>

<style lang="less" scoped>
.content {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}
.header_title {
	margin-left: 20rpx;
	font-weight: bold;
	font-size: 28rpx;
	color: #333333;
}
.header {
	margin-top: 46rpx;
	margin-left: 40rpx;
	margin-right: 40rpx;
}
.share_image {
	width: 40rpx;
}
.info_item {
	margin-top: 20rpx;

	.info_item_name {
		font-size: 24rpx;
		margin-left: 40rpx;
	}
	.info_item_value {
		font-size: 24rpx;
		font-weight: bold;
		color: #333333;
		margin-left: 60rpx;
	}
}
.list {
	margin-top: 20rpx;
	padding: 0 40rpx;
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-gap: 22rpx;

	.item {
		border-radius: 12rpx;
		box-shadow: 0rpx 4rpx 4rpx 0rpx rgba(0, 0, 0, 0.1);

		.item_range::before {
			content: '— ';
			color: #3d9c36;
		}
		.item_range::after {
			content: ' —';
			color: #3d9c36;
		}
		.item_range {
			text-align: center;
			font-size: 24rpx;
		}
	}
}
.map_container {
	padding: 20rpx 40rpx 0rpx 40rpx;
}
map {
	width: 100%;
}
</style>
